package com.gitee.cnzhangjie.webserviceserver.config;

import com.gitee.cnzhangjie.webserviceserver.service.IUserService;
import org.apache.cxf.Bus;
import org.apache.cxf.bus.spring.SpringBus;
import org.apache.cxf.transport.servlet.CXFServlet;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.apache.cxf.jaxws.EndpointImpl;

import javax.xml.ws.Endpoint;

import javax.annotation.Resource;

@Configuration
public class CxfConfig {
    @Resource
    private IUserService userService;
    /**
     * 注入Servlet 注意beanName不能为dispatcherServlet
     */
    @Bean
    public ServletRegistrationBean<CXFServlet> servletServletRegistrationBean() {
        return new ServletRegistrationBean<>(new CXFServlet(), "/a/*");
    }
    @Bean(name = Bus.DEFAULT_BUS_ID)
    public SpringBus springBus() {
        return new SpringBus();
    }
    @Bean
    public Endpoint endpoint() {
        EndpointImpl endpoint = new EndpointImpl(springBus(), userService);
        endpoint.publish("/b");
        return endpoint;
    }
}
